home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-includes / template-functions-comment.php < prev    next >
Encoding:
PHP Script  |  2004-05-10  |  9.2 KB  |  298 lines

  1. <?php
  2.  
  3. // Default filters for these functions
  4. add_filter('comment_author', 'wptexturize');
  5. add_filter('comment_author', 'convert_chars');
  6.  
  7. add_filter('comment_email', 'antispambot');
  8.  
  9. add_filter('comment_url', 'clean_url');
  10.  
  11. add_filter('comment_text', 'convert_chars');
  12. add_filter('comment_text', 'make_clickable');
  13. add_filter('comment_text', 'wpautop', 30);
  14. add_filter('comment_text', 'balanceTags');
  15. add_filter('comment_text', 'convert_smilies', 20);
  16.  
  17. add_filter('comment_excerpt', 'convert_chars');
  18.  
  19. function clean_url($url) {
  20.     if ('' == $url) return $url;
  21.     $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url);
  22.     $url = str_replace(';//', '://', $url);
  23.     $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
  24.     $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url);
  25.     return $url;
  26. }
  27.  
  28. function comments_number($zero='No Comments', $one='1 Comment', $more='% Comments', $number='') {
  29.     global $id, $comment, $tablecomments, $wpdb, $comment_count_cache;
  30.     if ('' == $comment_count_cache["$id"]) $number = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1'");
  31.     else $number = $comment_count_cache["$id"];
  32.     if ($number == 0) {
  33.         $blah = $zero;
  34.     } elseif ($number == 1) {
  35.         $blah = $one;
  36.     } elseif ($number  > 1) {
  37.         $blah = str_replace('%', $number, $more);
  38.     }
  39.     echo $blah;
  40. }
  41.  
  42. function comments_link($file='', $echo=true) {
  43.     global $id, $pagenow;
  44.     if ($file == '')    $file = $pagenow;
  45.     if ($file == '/')    $file = '';
  46.     if (!$echo) return get_permalink() . '#comments';
  47.     else echo get_permalink() . '#comments';
  48. }
  49.  
  50. function comments_popup_script($width=400, $height=400, $file='wp-comments-popup.php') {
  51.     global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript;
  52.     $wpcommentspopupfile = $file;
  53.     $wpcommentsjavascript = 1;
  54.     $javascript = "<script type=\"text/javascript\">\nfunction wpopen (macagna) {\n    window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n";
  55.     echo $javascript;
  56. }
  57.  
  58. function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') {
  59.     global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb, $tablecomments, $cookiehash;
  60.     global $querystring_start, $querystring_equal, $querystring_separator;
  61.     global $comment_count_cache, $single;
  62.     if (!$single) {
  63.     if ('' == $comment_count_cache["$id"]) {
  64.         $number = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1';");
  65.     } else {
  66.         $number = $comment_count_cache["$id"];
  67.     }
  68.     if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) {
  69.         echo $none;
  70.         return;
  71.     } else {
  72.         if (!empty($post->post_password)) { // if there's a password
  73.             if ($_COOKIE['wp-postpass_'.$cookiehash] != $post->post_password) {  // and it doesn't match the cookie
  74.                 echo('Enter your password to view comments');
  75.                 return;
  76.             }
  77.         }
  78.         echo '<a href="';
  79.         if ($wpcommentsjavascript) {
  80.             echo get_settings('siteurl') . '/' . $wpcommentspopupfile.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1';
  81.             //echo get_permalink();
  82.             echo '" onclick="wpopen(this.href); return false"';
  83.         } else {
  84.             // if comments_popup_script() is not in the template, display simple comment link
  85.             comments_link();
  86.             echo '"';
  87.         }
  88.         if (!empty($CSSclass)) {
  89.             echo ' class="'.$CSSclass.'"';
  90.         }
  91.         echo '>';
  92.         comments_number($zero, $one, $more, $number);
  93.         echo '</a>';
  94.     }
  95.     }
  96. }
  97.  
  98. function comment_ID() {
  99.     global $comment;
  100.     echo $comment->comment_ID;
  101. }
  102.  
  103. function comment_author() {
  104.     global $comment;
  105.     $author = apply_filters('comment_author', $comment->comment_author);
  106.     if (empty($author)) {
  107.         echo 'Anonymous';
  108.     } else {
  109.         echo $author;
  110.     }
  111. }
  112.  
  113. function comment_author_email() {
  114.     global $comment;
  115.     echo apply_filters('author_email', $comment->comment_author_email);
  116. }
  117.  
  118. function comment_author_link() {
  119.     global $comment;
  120.     $url = apply_filters('comment_url', $comment->comment_author_url);
  121.     $author = apply_filters('comment_author', $comment->comment_author);
  122.     if (!$author) $author = 'Anonymous';
  123.  
  124.     if (empty($url)) :
  125.         echo $author;
  126.     else:
  127.         echo "<a href='$url' rel='external'>$author</a>";
  128.     endif;
  129. }
  130.  
  131. function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
  132.     global $comment;
  133.     if (preg_match('|<trackback />|', $comment->comment_content))
  134.         echo $trackbacktxt;
  135.     elseif (preg_match('|<pingback />|', $comment->comment_content))
  136.         echo $pingbacktxt;
  137.     else
  138.         echo $commenttxt;
  139. }
  140.  
  141. function comment_author_url() {
  142.     global $comment;
  143.     echo apply_filters('comment_url', $comment->comment_author_url);
  144. }
  145.  
  146. function comment_author_email_link($linktext='', $before='', $after='') {
  147.     global $comment;
  148.     $email = apply_filters('comment_email', $comment->comment_author_email);
  149.     if ((!empty($email)) && ($email != '@')) {
  150.     $display = ($linktext != '') ? $linktext : stripslashes($email);
  151.         echo $before;
  152.         echo "<a href='mailto:$email'>$display</a>";
  153.         echo $after;
  154.     }
  155. }
  156.  
  157. function comment_author_url_link($linktext='', $before='', $after='') {
  158.     global $comment;
  159.     $url = apply_filters('comment_url', $comment->comment_author_url);
  160.  
  161.     if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) {
  162.     $display = ($linktext != '') ? $linktext : stripslashes($url);
  163.         echo "$before<a href='$url' rel='external'>$display</a>$after";
  164.     }
  165. }
  166.  
  167. function comment_author_IP() {
  168.     global $comment;
  169.     echo $comment->comment_author_IP;
  170. }
  171.  
  172. function comment_text() {
  173.     global $comment;
  174.     $comment_text = str_replace('<trackback />', '', $comment->comment_content);
  175.     $comment_text = str_replace('<pingback />', '', $comment_text);
  176.     echo apply_filters('comment_text', $comment_text);
  177. }
  178.  
  179. function comment_excerpt() {
  180.     global $comment;
  181.     $comment_text = str_replace('<trackback />', '', $comment->comment_content);
  182.     $comment_text = str_replace('<pingback />', '', $comment_text);
  183.     $comment_text = strip_tags($comment_text);
  184.     $blah = explode(' ', $comment_text);
  185.     if (count($blah) > 20) {
  186.         $k = 20;
  187.         $use_dotdotdot = 1;
  188.     } else {
  189.         $k = count($blah);
  190.         $use_dotdotdot = 0;
  191.     }
  192.     $excerpt = '';
  193.     for ($i=0; $i<$k; $i++) {
  194.         $excerpt .= $blah[$i] . ' ';
  195.     }
  196.     $excerpt .= ($use_dotdotdot) ? '...' : '';
  197.     echo apply_filters('comment_excerpt', $excerpt);
  198. }
  199.  
  200. function comment_date($d='') {
  201.     global $comment;
  202.     if ('' == $d) {
  203.         echo mysql2date(get_settings('date_format'), $comment->comment_date);
  204.     } else {
  205.         echo mysql2date($d, $comment->comment_date);
  206.     }
  207. }
  208.  
  209. function comment_time($d='') {
  210.     global $comment;
  211.     if ($d == '') {
  212.         echo mysql2date(get_settings('time_format'), $comment->comment_date);
  213.     } else {
  214.         echo mysql2date($d, $comment->comment_date);
  215.     }
  216. }
  217.  
  218. function comments_rss_link($link_text='Comments RSS', $commentsrssfilename = 'wp-commentsrss2.php') {
  219.     $url = comments_rss($commentsrssfilename);
  220.     echo "<a href='$url'>$link_text</a>";
  221. }
  222.  
  223. function comments_rss($commentsrssfilename = 'wp-commentsrss2.php') {
  224.     global $id;
  225.     global $querystring_start, $querystring_equal, $querystring_separator;
  226.  
  227.     if ('' != get_settings('permalink_structure')) {
  228.         $url = trailingslashit(get_permalink()) . 'feed/';
  229.     } else {
  230.         $url = get_settings('siteurl') . '/' . $commentsrssfilename.$querystring_start.'p'.$querystring_equal.$id;
  231.     }
  232.     return $url;
  233. }
  234.  
  235. function comment_author_rss() {
  236.     global $comment;
  237.     if (empty($comment->comment_author)) {
  238.         echo 'Anonymous';
  239.     } else {
  240.         echo htmlspecialchars(apply_filters('comment_author', $comment->comment_author));
  241.     }
  242. }
  243.  
  244. function comment_text_rss() {
  245.     global $comment;
  246.     $comment_text = str_replace('<trackback />', '', $comment->comment_content);
  247.     $comment_text = str_replace('<pingback />', '', $comment_text);
  248.     $comment_text = apply_filters('comment_text', $comment_text);
  249.     $comment_text = strip_tags($comment_text);
  250.     $comment_text = htmlspecialchars($comment_text);
  251.     echo $comment_text;
  252. }
  253.  
  254. function comment_link_rss() {
  255.     global $comment;
  256.     echo get_permalink($comment->comment_post_ID).'#comments';
  257. }
  258.  
  259. function permalink_comments_rss() {
  260.     global $comment;
  261.     echo get_permalink($comment->comment_post_ID);
  262. }
  263.  
  264. function trackback_url($display = true) {
  265.     global $id;
  266.     $tb_url = get_settings('siteurl') . '/wp-trackback.php/' . $id;
  267.     
  268.     if ('' != get_settings('permalink_structure')) {
  269.         $tb_url = trailingslashit(get_permalink()) . 'trackback/';
  270.     }
  271.     
  272.     if ($display) {
  273.         echo $tb_url;
  274.     } else {
  275.         return $tb_url;
  276.     }
  277. }
  278.  
  279.  
  280. function trackback_rdf($timezone = 0) {
  281.     global $id;
  282.     if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) {
  283.     echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  284.         xmlns:dc="http://purl.org/dc/elements/1.1/"
  285.         xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  286.         <rdf:Description rdf:about="';
  287.     the_permalink();
  288.     echo '"'."\n";
  289.     echo '    dc:identifier="';
  290.     the_permalink();
  291.     echo '"'."\n";
  292.     echo '    dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n";
  293.     echo '    trackback:ping="'.trackback_url(0).'"'." />\n";
  294.     echo '</rdf:RDF>';
  295.     }
  296. }
  297.  
  298. ?>